package com.ruoyi.tactics.algorithm;

import com.ruoyi.tactics.ZodiacResult;
import com.ruoyi.tactics.utils.CombineUtil;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 四中四
 */
public class FZFAlgorithm extends AbstractAlgorithm {
    @Override
    public Boolean isWin(ZodiacResult zodiacResult, String... code) {
        List<Integer> pms = zodiacResult.getPm();
        return isContains(pms, Arrays.stream(code)
                .map(Integer::valueOf)
                .toArray(Integer[]::new));
    }

    private Boolean isContains(List<Integer> pms, Integer... codes) {
        Set<Integer> pmSet = new HashSet<>();
        pmSet.addAll(pms);
        Set<Integer> codeSet = new HashSet<>();
        codeSet.addAll(Arrays.asList(codes));
        pmSet.retainAll(codeSet);
        Boolean isWin = pmSet.size() == 4;
        System.out.println("中奖号码:" + pms + "号码:" + Arrays.asList(codes) + ",是否中奖" + isWin);
        return isWin;
    }

    public static void main(String[] args) {
        FZFAlgorithm algorithm = new FZFAlgorithm();
        ZodiacResult zodiacResult = new ZodiacResult();
        zodiacResult.setPm(Arrays.asList(1, 2, 3, 4, 5, 46));

        List<List<Integer>> combinations = CombineUtil.combine(Arrays.asList(1, 2, 4, 5, 9, 10, 46).toArray(new Integer[0]), 4);
        Integer num = 0;
        for (List<Integer> combination : combinations) {
            Boolean isWin = algorithm.isWin(zodiacResult, combination.stream()
                    .map(String::valueOf)
                    .toArray(String[]::new));
            num += isWin ? 1 : 0;
        }
        System.out.println(combinations.size() + "组，中奖:" + num + "组");
    }
//    public static void main(String[] args) {
//        SZSAlgorithm algorithm = new SZSAlgorithm();
//        ZodiacResult zodiacResult = new ZodiacResult();
//        zodiacResult.setPm(Arrays.asList(1, 2, 3, 4, 5));
//        System.out.println(algorithm.isWin(zodiacResult, "1", "9", "3"));
//        System.out.println(algorithm.isWin(zodiacResult, "1", "2", "3"));
//    }
}
